package com.bdqn.tsyyds.controller;

import com.bdqn.tsyyds.entity.Permission;
import com.bdqn.tsyyds.entity.Student;
import com.bdqn.tsyyds.repository.StudentRepostiory;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.hibernate.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class LoginController {

    @Resource
    StudentRepostiory studentRepostiory;

    //配置欢迎页面
    @RequestMapping("/")
    public String indexsds() {
        return "login";
    }

    @RequestMapping("/login")
    public String index() {
        return "login";
    }

    @RequestMapping("/dologin")
    public String yzdengl(String stuName, String password, Model model, HttpSession session) {
        Student student = studentRepostiory.findByStdNameAndPassword(stuName, password);
        System.out.println(student.toString());
        if (student != null) {
            session.setAttribute("sessionuser", student);
            return "redirect:main";
        } else {
            model.addAttribute("msg", "错误重新输入");
            return "redirect:login";
        }
    }

    @RequestMapping("/dologin2")
    public String yzdengl() {
        return "redirect:main";
    }

    @RequestMapping("/main")
    public String main() {
        return "main";
    }

}